package com.srwl.mytx.domain;

import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Date;

public class MyFile implements Parcelable {
    public static final int FILE_TYPE_PICTURE = 0;
    public static final int FILE_TYPE_VIDEO = 1;
    public static final int FILE_TYPE_ADD_VIDEO = 2;
    public static final int FILE_TYPE_ADD_PICTURE = 3;
    public static final int FILE_TYPE_SELECT_REMOTE_FILE = 4;//在服务端文件仓库中选择，就是自己曾经各种发布中使用的图片和视频
    public static final int FILE_TYPE_PLACE_HOLDER = 5;// 空白选项，拖拽换位时候用于占位

    public static final int FILE_STATUS_LOCAL = 0;//文件还没有上传
    public static final int FILE_STATUS_UPLOAD_SUCCESS = 1;//文件已经上传，但是文件地址还没有保存在服务端
    public static final int FILE_STATUS_REMOTE = 2;//文件地址已经保存在服务端
    public static final int FILE_STATUS_UPLOAD_FAIL = 3;//本地文件上传失败

    private String id;

    private String uId;

    private Uri uri;//本地文件，

    private String url;

    private String videoCover;

    private Integer type;//类型

    private Integer status;//状态：0 本地；1 远程

    private Integer orderNum;

    private Date created;

    private boolean isCompress; //标记文件是否压缩

    public MyFile(String id, String uId, String url, Integer type, Date created) {
        this.id = id;
        this.uId = uId;
        this.url = url;
        this.type = type;
        this.created = created;
    }

    public MyFile() {
        super();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    public String getuId() {
        return uId;
    }

    public void setuId(String uId) {
        this.uId = uId == null ? null : uId.trim();
    }

    public Uri getUri() {
        return uri;
    }

    public void setUri(Uri uri) {
        this.uri = uri;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url == null ? null : url.trim();
    }


    public String getVideoCover() {
        return videoCover;
    }

    public void setVideoCover(String videoCover) {
        this.videoCover = videoCover;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Integer getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(Integer checkNum) {
        this.orderNum = checkNum;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public boolean isCompress() {
        return isCompress;
    }

    public void setCompress(boolean compress) {
        isCompress = compress;
    }

    public MyFile(Integer type) {
        this.type = type;
    }

    public MyFile(Integer type, String url) {
        this.url = url;
        this.type = type;
    }

    public MyFile(String url, Integer type, Integer status) {
        this.url = url;
        this.type = type;
        this.status = status;
    }
 public MyFile(Uri uri, Integer type, Integer status) {
        this.uri = uri;
        this.type = type;
        this.status = status;
    }

    public MyFile(String url, String videoCover, Integer type, Integer status) {
        this.url = url;
        this.videoCover = videoCover;
        this.type = type;
        this.status = status;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.uId);
        dest.writeParcelable(this.uri, flags);
        dest.writeString(this.url);
        dest.writeString(this.videoCover);
        dest.writeValue(this.type);
        dest.writeValue(this.status);
        dest.writeValue(this.orderNum);
        dest.writeLong(this.created != null ? this.created.getTime() : -1);
        dest.writeByte(this.isCompress ? (byte) 1 : (byte) 0);
    }

    protected MyFile(Parcel in) {
        this.id = in.readString();
        this.uId = in.readString();
        this.uri = in.readParcelable(Uri.class.getClassLoader());
        this.url = in.readString();
        this.videoCover = in.readString();
        this.type = (Integer) in.readValue(Integer.class.getClassLoader());
        this.status = (Integer) in.readValue(Integer.class.getClassLoader());
        this.orderNum = (Integer) in.readValue(Integer.class.getClassLoader());
        long tmpCreated = in.readLong();
        this.created = tmpCreated == -1 ? null : new Date(tmpCreated);
        this.isCompress = in.readByte() != 0;
    }

    public static final Creator<MyFile> CREATOR = new Creator<MyFile>() {
        @Override
        public MyFile createFromParcel(Parcel source) {
            return new MyFile(source);
        }

        @Override
        public MyFile[] newArray(int size) {
            return new MyFile[size];
        }
    };
}